package com.cupk.controller;

import com.cupk.pojo.Banner;
import com.cupk.pojo.Result;
import com.cupk.service.BannerService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    @PostMapping("/add")
    public Result add(@RequestBody Banner banner){
        bannerService.addBanner(banner);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<Banner>> list(){
        List<Banner> res = bannerService.getBannerList();
        return Result.success(res);
    }

    @GetMapping("/getList")
    public Result<List<Banner>> effectiveList(){
        List<Banner> res = bannerService.getEffectiveList();
        return Result.success(res);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Banner banner){
        bannerService.updateBanner(banner);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestParam Integer id){
        bannerService.deleteBanner(id);
        return Result.success();
    }
}
